﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace StoreWeb.system.message
{
    public partial class adduser : System.Web.UI.Page
    {
 
       // BLL.Customer bll = new BLL.Customer();
        BLL.member members = new BLL.member();
        Maticsoft.BLL.UserAdmin user = new Maticsoft.BLL.UserAdmin();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindData(hidwhere.Value);
            }
        }

        void bindData(string where)
        {
            if (where == "")
            {
                String loginname = user.GetModel(Convert.ToInt32(Request.Cookies["UserLogin"].Values[0])).loginname;//登录名
                String dealersid = user.GetModel(Convert.ToInt32(Request.Cookies["UserLogin"].Values[0])).dealersid;//经销商ID
                if (loginname == "admin")
                {//管理员查看全部
                    where = "";
                }
                else
                {
                    where += " dealersid='" + dealersid + "'";
                }

            }
            else
            {
                String loginname = user.GetModel(Convert.ToInt32(Request.Cookies["UserLogin"].Values[0])).loginname;//登录名
                String dealersid = user.GetModel(Convert.ToInt32(Request.Cookies["UserLogin"].Values[0])).dealersid;//经销商ID
                if (loginname == "admin")
                {//管理员查看全部
                    where += "";
                }
                else
                {
                    where += " and dealersid='" + dealersid + "'";
                }
            }

            Repeater1.DataSource = members.GetList(where);
            Repeater1.DataBind();
        }
        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            bindData(hidwhere.Value);
        }

        protected void btnserach_Click(object sender, EventArgs e)
        {
            string[] proSub = Request.Form.GetValues("s_province");
            string pro1 = proSub[s_province.SelectedIndex];

            string[] proSub2 = Request.Form.GetValues("s_city");
            string pro2 = proSub2[s_city.SelectedIndex];

            string[] proSub3 = Request.Form.GetValues("s_county");
            string pro3 = proSub3[s_county.SelectedIndex];

            string where = " 1=1 ";
             
            //if (name.Value != null && !string.IsNullOrEmpty(name.Value))
            //{
            //    where += " and customername like '%" + name.Value + "%'";
            //}
            //if (mobile.Value != null && !string.IsNullOrEmpty(mobile.Value))
            //{
            //    where += " and mobile like '%" + mobile.Value + "%'";
            //}

            if (mobile.Value != null && !string.IsNullOrEmpty(mobile.Value))
            {
                where += " and mobile like '%" + mobile.Value + "%'";
            }
            if (name.Value != null && !string.IsNullOrEmpty(name.Value))
            {
                where += " and name like '%" + name.Value + "%'";
            }

            if (pro1 != null && !string.IsNullOrEmpty(pro1))
            {
                where += " and s_province = '" + pro1 + "'";
            }

            if (pro2 != null && !string.IsNullOrEmpty(pro2))
            {
                where += " and s_city = '" + pro2 + "'";
            }

            if (pro3 != null && !string.IsNullOrEmpty(pro3))
            {
                where += " and s_county = '" + pro3 + "'";
            }

            hidwhere.Value = where;
            bindData(hidwhere.Value);
        }

        
    }
}